<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">
<meta name="referrer" content="same-origin">
<meta name="referrer" content="no-referrer" />








<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Netty之旅," />










<meta name="description" content="PoolChunk分配小内存过程&amp;emsp;&amp;emsp;1. 在Netty中内存以页为最小单位划分，假设分配2048KB大小的内存，如果使用PoolChunk直接分配一页，那真是太浪费了。参照Slab机制，Netty将一页内存进行更细致化的管理，使用PoolSubpage来分配小于一页的内存。&amp;emsp;&amp;emsp;2. PoolChunk内部维护一个PoolSubpage的数组subpages，">
<meta name="keywords" content="Netty之旅">
<meta property="og:type" content="article">
<meta property="og:title" content="Netty之旅（五）ByteBuf内存管理之PoolSubpage">
<meta property="og:url" content="http://yoursite.com/2018/08/08/Netty之旅（五）ByteBuf内存管理之PoolSubpage/index.html">
<meta property="og:site_name" content="矩阵编程">
<meta property="og:description" content="PoolChunk分配小内存过程&amp;emsp;&amp;emsp;1. 在Netty中内存以页为最小单位划分，假设分配2048KB大小的内存，如果使用PoolChunk直接分配一页，那真是太浪费了。参照Slab机制，Netty将一页内存进行更细致化的管理，使用PoolSubpage来分配小于一页的内存。&amp;emsp;&amp;emsp;2. PoolChunk内部维护一个PoolSubpage的数组subpages，">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-10-24T16:22:00.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Netty之旅（五）ByteBuf内存管理之PoolSubpage">
<meta name="twitter:description" content="PoolChunk分配小内存过程&amp;emsp;&amp;emsp;1. 在Netty中内存以页为最小单位划分，假设分配2048KB大小的内存，如果使用PoolChunk直接分配一页，那真是太浪费了。参照Slab机制，Netty将一页内存进行更细致化的管理，使用PoolSubpage来分配小于一页的内存。&amp;emsp;&amp;emsp;2. PoolChunk内部维护一个PoolSubpage的数组subpages，">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/08/08/Netty之旅（五）ByteBuf内存管理之PoolSubpage/"/>





  <title>Netty之旅（五）ByteBuf内存管理之PoolSubpage | 矩阵编程</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?7d29e6fba8e07d1a8af2414a20e5f2a6";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">矩阵编程</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-主页">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-主页"></i> <br />
            
            主页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-分类"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-所有文章">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-文章"></i> <br />
            
            所有文章
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/08/08/Netty之旅（五）ByteBuf内存管理之PoolSubpage/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="matrix">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="矩阵编程">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Netty之旅（五）ByteBuf内存管理之PoolSubpage</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-08-08T21:28:16+08:00">
                2018-08-08
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Netty之旅/" itemprop="url" rel="index">
                    <span itemprop="name">Netty之旅</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/08/08/Netty之旅（五）ByteBuf内存管理之PoolSubpage/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2018/08/08/Netty之旅（五）ByteBuf内存管理之PoolSubpage/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="PoolChunk分配小内存过程"><a href="#PoolChunk分配小内存过程" class="headerlink" title="PoolChunk分配小内存过程"></a>PoolChunk分配小内存过程</h3><p>&emsp;&emsp;1. 在Netty中内存以页为最小单位划分，假设分配2048KB大小的内存，如果使用PoolChunk直接分配一页，那真是太浪费了。参照Slab机制，Netty将一页内存进行更细致化的管理，使用PoolSubpage来分配小于一页的内存。<br>&emsp;&emsp;2. PoolChunk内部维护一个PoolSubpage的数组subpages，数组大小为1 &lt;&lt; maxOrder即默认为2048，相当于PoolChunk二叉树的叶子节点数量。<br>&emsp;&emsp;3. PoolSubpage每次分配内存的时候，只会去二叉树的叶子节点搜寻，当某一个节点被选中时，会根据节点的id，找到subpages数组种对应的PoolSubpage实例，如果该实例为空，则新建一个，然后使用PoolSubpage进行内存分配。看一下PoolChunk的内存分配入口<strong>allocateSubpage</strong>方法：<br><a id="more"></a><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">private long allocateSubpage(int normCapacity) &#123;</span><br><span class="line">        // Obtain the head of the PoolSubPage pool that is owned by the PoolArena and synchronize on it.</span><br><span class="line">        // This is need as we may add it back and so alter the linked-list structure.</span><br><span class="line">        // 内存主要还是依靠PoolArena来管理，这个先不说了</span><br><span class="line">        PoolSubpage&lt;T&gt; head = arena.findSubpagePoolHead(normCapacity);</span><br><span class="line">        synchronized (head) &#123;</span><br><span class="line">            int d = maxOrder; // subpages are only be allocated from pages i.e., leaves</span><br><span class="line">            // d深度为最大深度，所以这里会去叶子节点寻找空闲的节点</span><br><span class="line">            int id = allocateNode(d);</span><br><span class="line">            if (id &lt; 0) &#123;</span><br><span class="line">                return id;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            final PoolSubpage&lt;T&gt;[] subpages = this.subpages;</span><br><span class="line">            final int pageSize = this.pageSize;</span><br><span class="line"></span><br><span class="line">            freeBytes -= pageSize;</span><br><span class="line">            //获取在subpages中的索引</span><br><span class="line">            int subpageIdx = subpageIdx(id);</span><br><span class="line">            PoolSubpage&lt;T&gt; subpage = subpages[subpageIdx];</span><br><span class="line">            if (subpage == null) &#123;</span><br><span class="line">                subpage = new PoolSubpage&lt;T&gt;(head, this, id, runOffset(id), pageSize, normCapacity);</span><br><span class="line">                subpages[subpageIdx] = subpage;</span><br><span class="line">            &#125; else &#123;</span><br><span class="line">                subpage.init(head, normCapacity);</span><br><span class="line">            &#125;</span><br><span class="line">            return subpage.allocate();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></p>
<h3 id="PoolSubpage分配内存"><a href="#PoolSubpage分配内存" class="headerlink" title="PoolSubpage分配内存"></a>PoolSubpage分配内存</h3><p>&emsp;&emsp;看一下PoolSubpage构造函数：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">PoolSubpage(PoolSubpage&lt;T&gt; head, PoolChunk&lt;T&gt; chunk, int memoryMapIdx, int runOffset, int pageSize, int elemSize) &#123;</span><br><span class="line">        this.chunk = chunk;</span><br><span class="line">        this.memoryMapIdx = memoryMapIdx;</span><br><span class="line">        this.runOffset = runOffset;</span><br><span class="line">        this.pageSize = pageSize;</span><br><span class="line">        bitmap = new long[pageSize &gt;&gt;&gt; 10]; // pageSize / 16 / 64</span><br><span class="line">        init(head, elemSize);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></p>
<p>看一下这里的bitmap数组，他的大小是pageSize/16/64，默认pageSize=8192，即bitmap数组长度默认为8。bitmap反映了PoolSubpage中每一段内存的分配情况。elemSize是<strong>allocateSubpage(int normCapacity)</strong>入口的内存分配请求大小，这个大小是经过normalize的，最小为16，所以这里pageSize / 16，意思是将一页内存划分为512段，每一段内存是空闲还是被占用，使用一个bit位来标识，long类型可以标识64个bit位，所以，这里的bitmap数组长度只需要8就可以标识一页内存每一段的占用情况了。<br>看一下<strong>init</strong>函数：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">void init(PoolSubpage&lt;T&gt; head, int elemSize) &#123;</span><br><span class="line">        doNotDestroy = true;</span><br><span class="line">        this.elemSize = elemSize;</span><br><span class="line">        if (elemSize != 0) &#123;</span><br><span class="line">            maxNumElems = numAvail = pageSize / elemSize;</span><br><span class="line">            nextAvail = 0;</span><br><span class="line">            bitmapLength = maxNumElems &gt;&gt;&gt; 6;</span><br><span class="line">            if ((maxNumElems &amp; 63) != 0) &#123;</span><br><span class="line">                bitmapLength ++;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            for (int i = 0; i &lt; bitmapLength; i ++) &#123;</span><br><span class="line">                bitmap[i] = 0;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        addToPool(head);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></p>
<p>根据实际elemSize大小，来初始化bitmap数组。看一下PoolSubpage中实际分配内存的函数<strong>allocate()</strong>：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">long allocate() &#123;</span><br><span class="line">    if (elemSize == 0) &#123;</span><br><span class="line">        return toHandle(0);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    if (numAvail == 0 || !doNotDestroy) &#123;</span><br><span class="line">        return -1;</span><br><span class="line">    &#125;</span><br><span class="line">    // 寻找可用的内存段序号</span><br><span class="line">    final int bitmapIdx = getNextAvail();</span><br><span class="line">    // 获取该内存段在bitmap中的索引</span><br><span class="line">    int q = bitmapIdx &gt;&gt;&gt; 6;</span><br><span class="line">    // 舍弃高位，保证得到一个小于64的数字</span><br><span class="line">    int r = bitmapIdx &amp; 63;</span><br><span class="line">    assert (bitmap[q] &gt;&gt;&gt; r &amp; 1) == 0;</span><br><span class="line">    // 将bitmap中索引为q的数字，将相应bit位为不可用</span><br><span class="line">    bitmap[q] |= 1L &lt;&lt; r;</span><br><span class="line"></span><br><span class="line">    if (-- numAvail == 0) &#123;</span><br><span class="line">        removeFromPool();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    return toHandle(bitmapIdx);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>看一下<strong>getNextAvail</strong>到底做了什么，他又返回了什么东西：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">private int getNextAvail() &#123;</span><br><span class="line">        int nextAvail = this.nextAvail;</span><br><span class="line">        if (nextAvail &gt;= 0) &#123;</span><br><span class="line">            this.nextAvail = -1;</span><br><span class="line">            return nextAvail;</span><br><span class="line">        &#125;</span><br><span class="line">        return findNextAvail();</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></p>
<p>初始nextAvail=0，如果分配了，则将nextAvail置为-1，后来者会进入<strong>findNextAvail</strong>：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">private int findNextAvail() &#123;</span><br><span class="line">        final long[] bitmap = this.bitmap;</span><br><span class="line">        final int bitmapLength = this.bitmapLength;</span><br><span class="line">        // 遍历bitmap数组</span><br><span class="line">        for (int i = 0; i &lt; bitmapLength; i ++) &#123;</span><br><span class="line">            long bits = bitmap[i];</span><br><span class="line">            // 该位置还有未分配的空间</span><br><span class="line">            if (~bits != 0) &#123;</span><br><span class="line">                return findNextAvail0(i, bits);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        return -1;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private int findNextAvail0(int i, long bits) &#123;</span><br><span class="line">        final int maxNumElems = this.maxNumElems;</span><br><span class="line">        final int baseVal = i &lt;&lt; 6;</span><br><span class="line">        // 因为bitmap存储的是64位的long类型，每一位都代表一个内存段的分配情况</span><br><span class="line">        for (int j = 0; j &lt; 64; j ++) &#123;</span><br><span class="line">            if ((bits &amp; 1) == 0) &#123;</span><br><span class="line">                // 内存段的序号，必须小于最大的内存段数量</span><br><span class="line">                int val = baseVal | j;</span><br><span class="line">                if (val &lt; maxNumElems) &#123;</span><br><span class="line">                    return val;</span><br><span class="line">                &#125; else &#123;</span><br><span class="line">                    break;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            bits &gt;&gt;&gt;= 1;</span><br><span class="line">        &#125;</span><br><span class="line">        return -1;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></p>
<ol>
<li>遍历bitmap数组，如果为0，表示该位置还有未被分配的内存段，取出该bitmap上的long类型数字。</li>
<li>遍历该数字的每一个bit位，如果为0，而且该段内存序号小于最大的内存段，返回该段序号。</li>
</ol>
<p>好了，拿到的原来是elem的序号，继续回过头看上面的<strong>allocate()</strong>函数，拿到这个内存段序号后，返回toHandle(bitmapIdx)：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">private long toHandle(int bitmapIdx) &#123;</span><br><span class="line">        return 0x4000000000000000L | (long) bitmapIdx &lt;&lt; 32 | memoryMapIdx;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>精妙，只使用一个long类型的数字，将内存段elem序号放在高32位，memoryMapIdx放在低32位，一下子返回了两种信息。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Netty之旅/" rel="tag"># Netty之旅</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/08/08/Netty之旅（四）ByteBuf内存管理之PoolChunk/" rel="next" title="Netty之旅（四）ByteBuf内存管理之PoolChunk">
                <i class="fa fa-chevron-left"></i> Netty之旅（四）ByteBuf内存管理之PoolChunk
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/08/08/Netty之旅（六）ByteBuf内存管理之PoolArena/" rel="prev" title="Netty之旅（六）ByteBuf内存管理之PoolArena">
                Netty之旅（六）ByteBuf内存管理之PoolArena <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">matrix</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">47</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">18</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">19</span>
                  <span class="site-state-item-name">标签</span>
                
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#PoolChunk分配小内存过程"><span class="nav-number">1.</span> <span class="nav-text">PoolChunk分配小内存过程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#PoolSubpage分配内存"><span class="nav-number">2.</span> <span class="nav-text">PoolSubpage分配内存</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">matrix</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>
<div class=BbeiAn-info">
  浙ICP备 -
  <a href="http://www.beian.miit.gov.cn">18040498号</a>
  </a>
</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  

    
      <script id="dsq-count-scr" src="https://luyun.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'http://yoursite.com/2018/08/08/Netty之旅（五）ByteBuf内存管理之PoolSubpage/';
          this.page.identifier = '2018/08/08/Netty之旅（五）ByteBuf内存管理之PoolSubpage/';
          this.page.title = 'Netty之旅（五）ByteBuf内存管理之PoolSubpage';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://luyun.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  




	





  














  





  

  

  

  
  

  

  

  

</body>
</html>
